<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>上传文件</legend>
</fieldset>

<div class="layui-upload-drag" id="upload_open">
    <i class="layui-icon"></i>
    <p>点击上传,或将文件拖拽到此处上传开题报告</p>
</div>

<div class="layui-upload-drag" id="upload_design">
    <i class="layui-icon"></i>
    <p>点击上传,或将文件拖拽到此处上传毕业设计</p>
</div>

<div class="layui-upload-drag" id="upload_paper">
    <i class="layui-icon"></i>
    <p>点击上传,或将文件拖拽到此处上传毕业论文</p>
</div>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
    <legend>上传记录</legend>
</fieldset>

<script type="text/html" id="barDemo">
    {{#
    if(d.status == '已审核'){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">查看审核详情</a>
    {{#  }}}
</script>

<p style="color: red">注意:知道教师进行审核时只会审核最新提交的文件,请上传最新文件</p>
<table id="upload_table" class="layui-hide" lay-filter="upload_table"></table>
<<<<<<< HEAD
<!--prod-->
<script type="text/javascript"  src=http://47.95.143.128:8080/pageoffice.js id="po_js_main"></script>
<!--dev-->
<!--<script type="text/javascript"  src=http://localhost:8080/pageoffice.js id="po_js_main"></script>-->
=======
<script type="text/javascript"  src="/pageoffice.js" id="po_js_main"></script>
>>>>>>> dev
<script>
    layui.use(['upload','table','layer'], function() {
        var $ = layui.jquery,
            table=layui.table,
            layer=layui.layer,
            upload = layui.upload;


        // 上传历史表格的渲染
        table.render({
            elem: '#upload_table'
            ,url:'/api/v1/student/openAndPapers'
            ,method:'GET'
            ,parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.count,
                    "data": res.data
                };
            }
            ,cols: [[
                {checkbox: true, fixed: true}
                ,{width:80, title: '序号',type:'numbers'}
                ,{field:'id', width:80, title: '序号', sort: true,hide:true}
                ,{field:'fileName', width:392, title: '文件名称'}
                ,{field:'uploadTime', width:167, title: '上传时间', sort: true}
                ,{field:'status', width:88, title: '文件状态'}
                ,{width:88, title: '是否默认',templet:function(d){
                   if(d.last==true){
                       return "是";
                   } else { return "否"}
                  }}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:161}
            ]]
            ,page: false
        });


        // 上传开题报告
        upload.render({
            elem: '#upload_open'
            ,url: '/api/v1/student/openAndPaper'
            ,accept: 'file'
            ,field:'file'
            ,acceptMime:'.docx,.doc'
            ,before:function(obj){
                // 上传loading
                layer.load();
            }
            ,data:{"flag":"open"}
            ,done: function(res){
                // 关闭loading
                layer.closeAll('loading');
               if(res.code==0){
                   layer.msg("上传开题报告成功,请等待指导教师审核");
                   table.reload('upload_table');
               } else if(res.code==516){
                   layer.msg("已存在该文件,请勿重复上传")
               } else if(res.code==900){
                   layer.msg("当前不在允许的时间范围内,请勿重复进行操作");
               }
            }
        });

        // 上传毕业设计
        upload.render({
            elem: '#upload_design'
            ,url: '/api/v1/student/design',
            method:'POST'
            ,accept: 'file'
            ,exts: 'zip|rar|7z'
            ,acceptMime:'.zip,.rar'
            ,done: function(res){
                if(res.code==0){
                    layer.msg("上传毕业设计成功,请等待指导教师审核");
                    table.reload('upload_table');
                }  else if(res.code==900){
                    layer.msg("当前不在允许的时间范围内,请勿重复进行操作");
                } else {
                    layer.msg("上传毕业设计失败")
                }
            }
        });


        // 上传毕业论文
        upload.render({
            elem: '#upload_paper'
            ,url: '/api/v1/student/openAndPaper'
            ,accept: 'file'
            ,acceptMime:'.docx,.doc'
            ,before:function(obj){
                // 上传loading
                layer.load();
            }
            ,data:{"flag":"paper"}
            ,done: function(res){
                layer.closeAll('loading');
                if(res.code==0){
                    layer.msg("上传毕业论文成功,请等待指导教师审核");
                    table.reload('upload_table');
                } else if(res.code==516){
                    layer.msg("已存在该文件,请勿重复上传")
                }  else if(res.code==900){
                    layer.msg("当前不在允许的时间范围内,请勿重复进行操作");
                }
            }
        });


        // 查看审核详情
        table.on('tool(upload_table)', function(obj){
            let data = obj.data;
            let layEvent = obj.event;
            if(layEvent === 'edit'){
                if(data.fileName.indexOf("开题报告")!=-1){
<<<<<<< HEAD
                    // dev
                    //POBrowser.openWindowModeless('http://localhost:8080/teacher/check?studentId='+data.studentId+'&flag=open',"fullscreen=yes;resizable=yes");
                    //prod
                    POBrowser.openWindowModeless('http://47.95.143.128:8080/teacher/check?studentId='+data.studentId+'&flag=open',"fullscreen=yes;resizable=yes");
                } else if(data.fileName.indexOf("毕业论文")!=-1){
                    // dev
                    //POBrowser.openWindowModeless('http://localhost:8080/teacher/check?studentId='+data.studentId+'&flag=paper',"fullscreen=yes;resizable=yes");
                    // prod
                    POBrowser.openWindowModeless('http://47.95.143.128:8080/teacher/check?studentId='+data.studentId+'&flag=paper',"fullscreen=yes;resizable=yes");
=======
                    POBrowser.openWindowModeless('/api/v1/teacher/design/'+data.studentId+'/open',"fullscreen=yes;resizable=yes");
                } else if(data.fileName.indexOf("毕业论文")!=-1){
                    POBrowser.openWindowModeless('/api/v1/teacher/design/'+data.studentId+'/paper',"fullscreen=yes;resizable=yes");
>>>>>>> dev
                }
            }
        });
    });
</script>